`
https://leetcode.cn/problems/count-complete-subarrays-in-an-array/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var countCompleteSubarrays = function (nums) {
  const n = nums.length
  const need = new Set(nums).size
  let res = 0
  const cnt = new Array(2001).fill(0)
  let count = 0
  let left = 0, right = 0

  while (right < n) {
    const n1 = nums[right++]
    cnt[n1]++
    if (cnt[n1] === 1) count++

    // 关注 left - 1 及之前的合法性
    while (count === need) {
      const n2 = nums[left++]
      cnt[n2]--
      if (cnt[n2] === 0) count--
    }

    // 总共有left 个
    res += left
  }

  return res
};